﻿using Microsoft.AspNetCore.Mvc;
using mozhi.smarterp.Business.Enums;
using mozhi.smarterp.Business.Purchases.Order;
using mozhi.smarterp.Business.Purchases.Requisition;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;

namespace mozhi.smarterp.Business.Controllers.Purchases
{
    [RemoteService]
    [Route("api/v1/purchases/orders")]
    public class PurchaseOrderController : BusinessController
    {
        private IPurchaseOrderAppService _appService;

        public PurchaseOrderController(IPurchaseOrderAppService appService)
        {
            _appService = appService;
        }

        [HttpGet]
        [Route("{id}")]
        public async Task<PurchaseOrderDto> GetAsync(Guid id)
        {
            return await _appService.GetAsync(id);
        }

        [HttpGet]
        public async Task<PagedResultDto<PurchaseOrderDto>> GetAsync(PurchaseOrderResultRequestDto filter)
        {
            return await _appService.GetListAsync(filter);
        }

        [HttpPost]
        public async Task<PurchaseOrderDto> CreateAsync(PurchaseOrderCreateDto input)
        {
            return await _appService.CreateAsync(input);
        }

        [HttpPut]
        public async Task<PurchaseOrderDto> UpdateAsync(PurchaseOrderUpdateDto input)
        {
            return await _appService.UpdateAsync(input);
        }

        [HttpPut]
        [Route("{id}/status/{status}")]
        public async Task UpdateStatusAsync(Guid id, DocumentStatusType status)
        {
            await _appService.UpdateStatusAsync(id, status);
        }

        [HttpDelete]
        [Route("{id}")]
        public async Task DeleteAsync(Guid id)
        {
            await _appService.DeleteAsync(id);
        }

        [HttpPost]
        [Route("{id}/receipt")]
        public async Task PushReceiptAsync(Guid id)
        {
            await _appService.PushReceiptAsync(id);
        }

        [HttpPost]
        [Route("{id}/payment-requisitions")]
        public async Task PushPaymentRequisitionAsync(Guid id)
        {
            await _appService.PushPaymentRequisitionAsync(id);
        }
    }
}
